<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>提莫攻击</title>
</head>

<body>
  <script>
    function array(a, b) {
      let num = 0
      for (let i = 1; i < a.length; i++) {// i = 1
        // sum = a[1] - a[0] = 2 - 1
        // 判断两个数相减的结果是否小于2
        let sum = a[i] - a[i - 1] // sum = 1
        // 小于二的话，就
        if (sum < b) {
          num += sum
        } else {
          num += b
        }
      }
      return num + b
    };
    console.log(array([1, 1], 2))
  </script>
</body>

</html>